<template>

  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="入库批次号" prop="rukuNos">
                <el-input v-model="queryParams.rukuNos" placeholder="请输入入库批次号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="出库人" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入出库人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
              <!--<el-form-item label="领料日期" prop="useDate">
                  <el-date-picker clearable v-model="queryParams.useDate"
                                  type="date" value-format="yyyy-MM-dd" placeholder="请选择领料日期">
                  </el-date-picker>
              </el-form-item>-->
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

    <!--<el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['develop:GoodsSaleMaterialDetail:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
            <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                    @click="handleUpdate" v-hasPermi="['develop:GoodsSaleMaterialDetail:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
            <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                           v-hasPermi="['develop:GoodsSaleMaterialDetail:remove']">删除</el-button>
            </el-popconfirm>
        </el-col>
        <el-col :span="1.5">
            <el-button type="warning" plain icon="el-icon-download" size="mini"
                    @click="handleExport" v-hasPermi="['develop:GoodsSaleMaterialDetail:export']">导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="供应商名称" align="center" prop="supplierName" show-overflow-tooltip/>
            <el-table-column label="订单编号" align="center" prop="projectNo"show-overflow-tooltip/>
            <el-table-column label="产品编码" align="center" prop="goodsCode" show-overflow-tooltip/>
            <el-table-column label="产品名称" align="center" prop="goodsName" show-overflow-tooltip/>
            <el-table-column label="产品型号" align="center" prop="goodModel" show-overflow-tooltip/>
            <el-table-column label="计量单位" align="center" prop="goodsUnit"/>
            <el-table-column label="产品数量" align="center" prop="goodsCount"/>
            <el-table-column label="产品单价" align="center" prop="goodsBuyPrice"/>
            <el-table-column label="产品总价" align="center" prop="goodsBuyTotal"/>
            <el-table-column label="使用订单编号" align="center" prop="proNo" show-overflow-tooltip/>
            <!--<el-table-column label="使用产品编号" align="center" prop="goodCode"/>
            <el-table-column label="使用产品型号" align="center" prop="goodXinghao"/>-->
            <el-table-column label="使用数量" align="center" prop="useCount"/>
            <el-table-column label="入库批次号" align="center" prop="rukuNos" show-overflow-tooltip/>
            <el-table-column label="出库人" align="center" prop="userName"/>
            <el-table-column label="出库日期" align="center" prop="useDate" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.useDate, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <!-- <el-button size="mini" type="text" icon="el-icon-edit"
                            @click="shengchanDo(scope.row)" >生产过程</el-button> -->
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                   style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                   v-hasPermi="['develop:GoodsSaleMaterialDetail:remove']">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <goodsSaleMaterialDetail-form ref="form" @ok="getList"></goodsSaleMaterialDetail-form>
        <shengchanDo-form ref="shengchanDoForm" @ok="getList"></shengchanDo-form>
  </el-dialog>
</template>

<script>
    import { deleteAction, getAction } from '@/api/manage'
    import GoodsSaleMaterialDetailForm from '@/views/develop/goodsSaleMaterialDetail/module/GoodsSaleMaterialDetailForm'
    import ShengchanDoForm from '@/views/develop/goodsSale/module/ShengchanDoForm'

    export default {
        name: "ChoseGoodsDeatilFormList",
        components: {
            GoodsSaleMaterialDetailForm,
            ShengchanDoForm,
        },
        data() {
            return {
                title: "",
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 销售产品物料选用明细表格数据
                dataList: [],
                open: false,
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    gsaleId: null,
                    goodsId: null,
                    goodsCode: null,
                    goodsName: null,
                    goodsType: null,
                    goodsBrand: null,
                    goodModel: null,
                    goodsUnit: null,
                    goodsCount: null,
                    goodsBuyPrice: null,
                    goodsBuyTotal: null,
                    supplierId: null,
                    supplierName: null,
                    saleName: null,
                    projectId: null,
                    projectName: null,
                    projectNo: null,
                    status: null,
                    proId: null,
                    proNo: null,
                    goodSaleId: null,
                    goodCode: null,
                    goodXinghao: null,
                    useCount: null,
                    rukuId: null,
                    rukuNos: null,
                    userName: null,
                    userId: null,
                    useDate: null,
                    materialId: null,
                    yifahuomingxiId: null,
                },
                url: {
                    list:'/goodsSaleMaterialDetail/goodsSaleMaterialDetail/list',
                    remove:'/goodsSaleMaterialDetail/goodsSaleMaterialDetail/',
                    export:'/goodsSaleMaterialDetail/goodsSaleMaterialDetail/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            shengchanDo(row){
              this.$refs.shengchanDoForm.show(row);
            },
            show(row,status) {
              this.open = true;
              this.title = "销售产品物料选择明细";
              this.queryParams.yifahuomingxiId=row.id;
              this.queryParams.status=status;
              this.getList();
            },
            /** 查询销售产品物料选用明细列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `goodsSaleMaterialDetail_${new Date().getTime()}.xlsx`)
            },
  }
};
</script>
